import { defineStore } from 'pinia'

export const useTagStore = defineStore('tags', () => {
  // ref 就是 state状态
  // computed 就是 getters
  // methods 就是 actions

  // 初始状态
  const tags = ref([{ name: 'home', label: '首页', path: '/' }])

  // 添加标签
  const addTag = tag => {
    if (tags.value.some(item => item.name === tag.name)) return
    tags.value.push(tag)
  }

  // 删除标签
  const removeTag = tag => {
    const index = tags.value.findIndex(item => item.name === tag.name)
    if (index === -1) return
    tags.value.splice(index, 1)
  }

  return {
    tags,
    addTag,
    removeTag,
  }
})
